<script setup>
import { useRoute } from 'vue-router';
import {get} from "../../util/request.js";
import {ref} from "vue";

const route = useRoute();
const schoolName = route.params.schoolName;
const list0= ref([]);
const detailVisible= ref(false);
const activeIndex= ref(null);
const expandedIndex = ref(null);

const showDetails = (index) => {
  expandedIndex.value = expandedIndex.value === index ? null : index;
}
const onTabChange = (tab) => {
    try {
      let url;
      switch (tab) {
        case '招生简章':
          url =`home/zhaosheng/selectBySchoolName/${schoolName}` ;
          break;
        case '考研分数线':
          url = `home/fenshuxian/selectBySchoolName/${schoolName}`;
          break;
        case '考研招录比':
          url = `home/baolubi/selectBySchoolName/${schoolName}`;
          break;
        case '硕士导师':
          url = `home/daoshi/selectBySchoolName/${schoolName}`;
          break;
        default:
          url = `home/zhaosheng/selectBySchoolName/${schoolName}`;
      }
      get(url).then(response => {
        list0.value = response.data
        console.log(response.data)
      });
    } catch (error) {
      console.error('Error fetching data:', error);
    }
  }

</script>
<template>
  <van-row style="padding: 16px 20px;">
    <van-col span="4" style="display: flex; align-items: center;">
      <router-link to="javascript:void(0)" class="back-button" @click="$router.go(-1)">
        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M15.41 7.41L14 6L8 12L14 18L15.41 16.59L10.83 12L15.41 7.41Z" fill="#000000"/>
        </svg>
      </router-link>
    </van-col>

    <van-col span="16">
      <span style="font-size: 18px; font-weight: bold; display: block; text-align: center;">{{schoolName }}</span>
    </van-col>
  </van-row>
  <van-tabs  @change="onTabChange">
    <van-tab title="招生简章" name="招生简章">
      <div class="card-container">
        <div v-for="(item, index) in list0" :key="index" class="card" @click.prevent="showDetails(index)">
          <div class="card-content">
            <h5 class="bold-title">{{ item.title }}</h5>
            <p v-if="expandedIndex !== index && item.content!=null">{{ item.content.slice(0, 50) + '...' }}</p>
            <p v-if="expandedIndex === index">{{ item.content }}</p>
          </div>
          <div class="card-header">
            <span class="view-count">{{ item.views }}阅读</span>
          </div>
        </div>
      </div>
    </van-tab>
    <van-tab title="考研分数线" name="考研分数线">
      <div class="card-container">
        <span>{{schoolName}}硕士考研近三年复试分数线</span>
        <van-row>
          <van-col span="3">年份</van-col>
          <van-col span="3">政治</van-col>
          <van-col span="3">外语</van-col>
          <van-col span="3">专业一</van-col>
          <van-col span="3">专业二</van-col>
          <van-col span="3">总分</van-col>
          <van-col span="3">复试</van-col>
          <van-col span="3">录取</van-col>
        </van-row>
        <div v-for="(item, index) in list0" :key="index"
                     class="card">
          <van-row>
            <van-col span="3">{{item.year}}</van-col>
            <van-col span="3">{{item.zhengzhi}}</van-col>
            <van-col span="3">{{item.waiyu}}</van-col>
            <van-col span="3">{{item.zhuanye1}}</van-col>
            <van-col span="3">{{item.zhuanye2}}</van-col>
            <van-col span="3">{{item.zongfen}}</van-col>
            <van-col span="3">{{item.fushi}}</van-col>
            <van-col span="3">{{item.luqu}}</van-col>
          </van-row>
      </div>
      </div>
    </van-tab>
    <van-tab title="考研招录比" name="考研招录比">
      <div class="card-container">
        <span>{{schoolName}}硕士考研近三年报录比情况</span>
        <van-row>
          <van-col span="4" offset="1">年份</van-col>
          <van-col span="4" offset="1">专业</van-col>
          <van-col span="4" offset="1">报名人数</van-col>
          <van-col span="4" offset="1">录取人数</van-col>
          <van-col span="4">报录比</van-col>
        </van-row>
        <div v-for="(item, index) in list0" :key="index"
             class="card">
          <van-row>
            <van-col span="4" offset="1">{{item.year}}</van-col>
            <van-col span="4" offset="1">{{item.zhuanye}}</van-col>
            <van-col span="4" offset="1">{{item.renshu}}</van-col>
            <van-col span="4" offset="1">{{item.luqurenshu}}</van-col>
            <van-col span="4">{{item.bilv}}</van-col>
          </van-row>
        </div>
      </div>
    </van-tab>
    <van-tab title="硕士导师" name="硕士导师">
      <div class="card-container">
        <div v-for="(item, index) in list0" :key="index"  class="card" @click.prevent="showDetails(index)">
          <img :src="item.imageUrl" alt="图片" style="width: 100px; height: 100px;">
          <div class="card-content">
            <div class="name">
              <span>{{ item.name }}</span>
              <span>{{ item.zhicheng }}</span>
            </div>
            <p v-if="expandedIndex !== index && item.jisshao!=null">{{ item.jisshao.slice(0, 10) + '...' }}</p>
            <p v-if="expandedIndex === index">{{ item.jisshao }}</p>
            <p>{{ item.danwei }}</p>
          </div>
        </div>
      </div>
    </van-tab>
  </van-tabs>
</template>
<style scoped>
.bold-title {
  font-weight: bold;
  color: #333;
}

/* 内容卡片样式 */
.card {
  position: relative; /* 为了绝对定位子元素（如阅读量） */
  color: #333;
}

/* 阅读量样式 */
.view-count {
  position: absolute;
  bottom: 0;
  left: 0;
  background-color: rgba(255, 255, 255, 0.8); /* 考虑到背景透明度，以适应不同颜色的卡片 */
  padding: 4px 8px;
  color: #333;
  font-size: 14px;
  border-radius: 4px 0 0 4px;
}

/* 如果有其他样式需求，比如图片样式、卡片头部样式等，也应在这里定义 */
.card-header,
.card-content1 {

}

.card {
  display: flex;
  align-items: center;
}

.card-content1 {
  flex: 1;
}

.name {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}

.card-content p {
  margin-bottom: 5px;
}
/* 根据需要添加具体样式 */
</style>
